package jwei.apps.indextank.adapters;

import jwei.apps.indextank.R;
import jwei.apps.indextank.db.IngredientCache.IngredientsCache;
import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

public class IngredientsCursorAdapter extends SimpleCursorAdapter {

    private int layout;

    public IngredientsCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
        super(context, layout, c, from, to);
        this.layout = layout;
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        final LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(layout, parent, false);
        return v;
    }

    @Override
    public void bindView(View v, Context context, Cursor c) {
        String ingredientName = c.getString(c.getColumnIndex(IngredientsCache.NAME));
        TextView ingText = (TextView) v.findViewById(R.id.ingredient_name);
        ingText.setText(ingredientName);
    }

}
